package IOStreamStudy.fileWriter;

import org.junit.Test;

import java.io.FileWriter;
import java.io.IOException;

/**
 * 写入字符流
 * */
public class FileWriterDemo {

    @Test
    public void fileWriter() throws IOException {
        String filePath = "D:\\all_projects\\java_projects\\java_ij\\springMVC\\NetWork\\src\\cn" +
                "\\usts\\edu\\IOStreamStudy\\fileWriter\\a.txt";
        FileWriter fileWriter = new FileWriter(filePath);
        String msg = "你好java,io流知识学习中.......";
        fileWriter.write(msg);
        fileWriter.close();
    }

    @Test
    public void fileWriter02() throws IOException {
        char[] chars = {'我','是','j','a','v','a','程','序','员'};
        String filePath = "D:\\all_projects\\java_projects\\java_ij\\springMVC\\NetWork\\src\\cn" +
                "\\usts\\edu\\IOStreamStudy\\fileWriter\\b.txt";//没有自动创建
        FileWriter fileWriter = new FileWriter(filePath,true);//是否追加

        fileWriter.write(chars);
        fileWriter.write("你好java".toCharArray(),0,3);
        // 关闭流
        fileWriter.close();
    }
}
